# -*- coding: utf-8 -*-
import unittest
import os.path


from add_player import *
from presenter_mock import *


class APTest(unittest.TestCase):
    def setUp(self):
        pass

    def test_add_when_empty(self):
        """
        Test empty list of users
        """
        gamestate = GameState(Players([]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        screen = AddPlayerScreen(gamestate, presenter)
        screen.update_name('AAA')
        screen.on_add_user_pressed()
        self.assertEquals(gamestate.current_added_player.name, 'AAA')

    def test_add_when_user_exist(self):
        """
        Test list of users with one player
        """
        gamestate = GameState(Players([Player('User1', [])]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        screen = AddPlayerScreen(gamestate, presenter)
        screen.update_name('AAA')
        screen.on_add_user_pressed()
        self.assertEquals(gamestate.current_added_player.name, 'AAA')
        self.presenter = PresenterMock(Phase.START_GAME)

    def test_empty_name(self):
        """
        Test unacceptable player names
        """
        gamestate = GameState(Players([Player('User1', [])]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        screen = AddPlayerScreen(gamestate, presenter)
        screen.update_name('')
        self.assertEquals(screen.to_add_button.enabled, False)

    def test_duplicate_name(self):
        """
        Test unacceptable player names
        """
        gamestate = GameState(Players([Player('User1', [])]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        tmp = AddPlayerScreen(gamestate, presenter)
        tmp.update_name('User1')
        self.assertEquals(tmp.to_add_button.enabled, False)


if __name__ == '__main__':
    unittest.main()
